home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / dev / c / EGCSWOSAlib.lha / src.lha / CreateTask.c < prev    next >
C/C++ Source or Header  |  1998-08-02  |  2KB  |  72 lines

  1. /*
  2. ** amiga.lib for vbcc-PowerOpen/WarpOS
  3. **
  4. ** CreateTask() - creates an M68k task (or should it create a PPC task?)
  5. **
  6. ** V0.1 15-Mar-98 phx
  7. **      created
  8. */
  9.  
  10. #include <exec/tasks.h>
  11. #include <exec/memory.h>
  12. #include <exec/execbase.h>
  13. #include <clib/alib_protos.h>
  14. #include <proto/exec.h>
  15.  
  16. struct ExecBase *SysBase;
  17.  
  18. struct newMemList
  19. {
  20.   struct Node nml_Node;
  21.   UWORD nme_NumEntries;
  22.   struct MemEntry nml_ME[2];
  23. };
  24.  
  25. const struct newMemList MemTemplate =
  26. { {0,},
  27.   2,
  28.   { {MEMF_CLEAR|MEMF_PUBLIC, (sizeof(struct Task) + 63) & ~31},
  29.     {MEMF_CLEAR, 0} }
  30. };
  31.  
  32. struct Task *CreateTask(STRPTR name, LONG pri, APTR initpc, ULONG stacksize)
  33. {
  34.   struct Task *newtask,*task2;
  35.   struct newMemList nml;
  36.   struct MemList *ml;
  37.  
  38.   stacksize=(stacksize+63)&~31;
  39.   {
  40.     long *p1,*p2;
  41.     int i;
  42.  
  43.     for (p1=(long *)&nml,p2=(long*)&MemTemplate,i=7; i; *p1++=*p2++,i--) ;
  44.     *p1=stacksize;
  45.   }
  46. /*  if (!(((unsigned int)ml=AllocEntry((struct MemList *)&nml)) & (1<<31)))*/
  47. /*  was dieser gcc alles als lvalue durchgehen laesst...    */
  48.   ml=AllocEntry((struct MemList *)&nml);
  49.   if(!((unsigned int)ml&(1<<31)))
  50.   {
  51.     newtask= (struct Task *)(((ULONG)(ml->ml_ME[0].me_Addr)+31)&~31);
  52.     newtask->tc_Node.ln_Type=NT_TASK;
  53.     newtask->tc_Node.ln_Pri=pri;
  54.     newtask->tc_Node.ln_Name=name;
  55.     newtask->tc_SPLower=(APTR)(((ULONG)(ml->ml_ME[1].me_Addr)+31)&~31);
  56.     newtask->tc_SPReg=(APTR)((ULONG)newtask->tc_SPLower+stacksize);
  57.     newtask->tc_SPUpper=newtask->tc_SPReg;
  58.     NewList(&newtask->tc_MemEntry);
  59.     AddHead(&newtask->tc_MemEntry,(struct Node *)ml);
  60.     task2=(struct Task *)AddTask(newtask,initpc,0);
  61.     if (SysBase->LibNode.lib_Version>36 && !task2)
  62.     {
  63.       FreeEntry(ml); newtask=NULL;
  64.     }
  65.   }
  66.   else
  67.     newtask=NULL;
  68.  
  69.   return newtask;
  70. }
  71.  
  72.